//
//  ThemeCellAdapter.swift
//  Bee
//
//  Created by kyson on 15/12/31.
//  Copyright © 2015年 kyson. All rights reserved.
//

import UIKit

class ThemeCellAdapter: NSObject ,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UICollectionViewDelegate {
    
    var titles:NSArray = ["推荐","美女","生活","其他"]
    
    private var selectedCellNum:NSNumber = 0
    
    @available(iOS 6.0, *)
    internal func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{
        var number: Int!
        switch(section){
        case 0:
            number = titles.count
            break
            //        case 1:
            //            number = 4
            //            break
            //        case 2:
            //            number = 6
            //            break
        default:
            break
        }
        return number
    }
    
    // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
    @available(iOS 6.0, *)
    internal func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
        var cell: UICollectionViewCell!
        switch(indexPath.section){
        case 0:
            cell = collectionView.dequeueReusableCellWithReuseIdentifier("theme", forIndexPath: indexPath)
            let themeCell = cell as! ThemeCell
            //设置是否选中
            if(indexPath.row == self.selectedCellNum.integerValue){
                themeCell.isButtonSelected = true
            }else{
                themeCell.isButtonSelected = false
            }

            themeCell.cellTitle = titles[indexPath.row] as! String
            themeCell.cellClickCallBack = {
                self.selectedCellNum = NSNumber.init(integer: indexPath.row)
                //先设置所有的cell都是未选中状态
                for index in 0...(self.titles.count-1){
                    let tempIndexPath = NSIndexPath.init(forItem: index, inSection: 0)
                    let tempCell = collectionView .cellForItemAtIndexPath(tempIndexPath) as! ThemeCell
                    tempCell.isButtonSelected = false
                }
                
                themeCell.isButtonSelected = true
            }
            break
            //        case 1:
            //            cell = collectionView.dequeueReusableCellWithReuseIdentifier("editpic", forIndexPath: indexPath)
            //            break
            //        case 2:
            //            cell = collectionView.dequeueReusableCellWithReuseIdentifier("editpic", forIndexPath: indexPath)
            //            break
        default:
            break
        }
        return cell
    }
    
    
    //    internal func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize{
    //        return CGSizeMake(UIScreen.mainScreen().bounds.width, 8)
    //    }
    
    internal func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize{
        var size:CGSize!
        switch(indexPath.section){
        case 0:
            size = CGSizeMake(50, 30)
            break
            //        case 1:
            //            size = CGSizeMake(50, 40)
            //            break
            //        case 2:
            //            size = CGSizeMake(60, 30)
            //            break
        default:
            break
        }
        return size
    }
    
    
    //    internal func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat{
     //    }
    //
    //
    //    internal func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets{
    //        return UIEdgeInsetsMake(0, 0, 0, 0)
    //    }
    //    
    internal func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int{
        return 1
    }
    
}
